package test.smiddus.nl;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.location.LocationManager;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class RowmodeIntro extends Activity{
	Activity context = this;
	private LocationManager lm;

	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.rowmodeintro);
        checkGPSSettings();
        //TODO check internet connection;
        
        ((Button)findViewById(R.id.start_sensors)).setOnClickListener(new View.OnClickListener(){
			public void onClick(View v){
				Intent anIntent = new Intent(context, Rowmode.class);
				context.startActivity(anIntent);
			}
		});
    }
	//usual Location services initialization
	private LocationManager getLocationManager() {
		if (this.lm == null)
			this.lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
		return this.lm;
	}

	private void checkGPSSettings()
	{
		//show GPS settings
		if( !getLocationManager().isProviderEnabled(android.location.LocationManager.GPS_PROVIDER ) )
		{
			Toast.makeText( this, "Please turn on GPS", Toast.LENGTH_LONG ).show();			
			//Output device name
			Log.i("device", Build.DEVICE);	
			//Output model name of device (in this case only the firs 3 letters, which are "HTC")
			Log.i("handy-model", Build.MODEL.substring(0, 3));
			
			//for HTC devices
			if(Build.MODEL.substring(0, 3).equals("HTC")){
				Intent myIntent = new Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS);
				startActivity(myIntent);
			}
			//for other devices
			else{
				Intent myIntent = new Intent( Settings.ACTION_SECURITY_SETTINGS );
				startActivity(myIntent);
			}		
		}
	}

}

